--[[ Tronex 2019/11/27 Basic light commands controller Currently disabled until the issue with DX8 is fixed To enable the script, uncomment lines inside on_game_start() --]] local d_key = "DIK_F6" local commands = { [1] = { name= "ui_mm_video_basic_gamma", command= "r__gamma", def= 1, min= 0.5, max= 2.2, step= 0.1 }, [2] = { name= "ui_mm_video_basic_contrast", command= "r__saturation", def= 1, min= 0, max= 2, step= 0.1 }, [3] = { name= "ui_mm_video_basic_brightness", command= "r__exposure", def= 1, min= 0.5, max= 4, step= 0.1 }, } local precision = 6 -- allowed number of zeros function on_key_release(key) if (key == DIK_keys[d_key]) then if db.actor and db.actor:alive() and (not device():is_paused()) --and (not (ui and ui:IsShown())) then start() end end end function actor_on_first_update() local RENDERER = get_console_cmd(0,"renderer") if (RENDERER == 'renderer_r1') then local hud = get_hud() local cs = hud:GetCustomStatic("dx8_fill_shader") if (not cs) then printdbg("- UILightControl | Started dx8_fill_shader") hud:AddCustomStatic("dx8_fill_shader") end end end function on_game_start() --RegisterScriptCallback("on_key_release",on_key_release) --RegisterScriptCallback("actor_on_first_update",actor_on_first_update) end ------------------------------------------------------------------- GUI = nil -- instance, don't touch function start() exec_console_cmd("main_menu off") --device():pause(true) hide_hud_inventory() if (not GUI) then GUI = UILightControl() end if (GUI) and (not GUI:IsShown()) then GUI:ShowDialog(true) Register_UI("UILightControl","ui_ctrl_lighting") end end ------------------------------------------------------------------- class "UILightControl" (CUIScriptWnd) function UILightControl:__init() super() self:InitControls() end function UILightControl:__finalize() end function UILightControl:InitControls() self:SetWndRect (Frect():set(0,0,1024,768)) self:SetAutoDelete(true) self.xml = CScriptXmlInit() local xml = self.xml xml:ParseFile ("ui_options.xml") self.dialog = xml:InitStatic("ctrl_lighting", self) xml:InitFrame("ctrl_lighting:frame", self.dialog) xml:InitStatic("ctrl_lighting:cap_main",self.dialog) self.scroll = xml:InitScrollView("ctrl_lighting:scroll", self.dialog) self.scroll:Clear() self.Track = {} self.Value = {} self.Num = {} for i=1,#commands do local _st = xml:InitStatic("ctrl_lighting:st", nil) local tbl = commands[i] local name = tbl.name local val = get_console_cmd(0,tbl.command) val = tonumber(val) local cap = xml:InitStatic("ctrl_lighting:cap", _st) cap:TextControl():SetText( game.translate_string(name) ) self.Track[i] = xml:InitTrackBar("ctrl_lighting:track", _st) self.Track[i]:SetStep(tbl.step) self.Track[i]:SetOptFBounds(tbl.min, tbl.max) self.Track[i]:SetFValue(val) self.Value[i] = val self.Num[i] = xml:InitTextWnd("ctrl_lighting:num", _st) self.Num[i]:SetText(val) self.scroll:AddWindow(_st, true) _st:SetAutoDelete(true) end end function UILightControl:Callback_Track(i, val) local cmd = commands[i].command if cmd and val then exec_console_cmd(cmd .. " " .. val) self.Num[i]:SetText(val) end end function UILightControl:Update() CUIScriptWnd.Update(self) -- Hack to simulate tracing method for TrackBar value changes. TODO: add callback support for CUITrackBar in engine, this is just silly for i,ctrl in pairs(self.Track) do if ctrl:IsCursorOverWindow() then local val = round_idp(ctrl:GetFValue(), precision) if (val ~= self.Value[i]) then self.Value[i] = val self:Callback_Track(i, val) return end end end end function UILightControl:OnKeyboard(dik, keyboard_action) local res = CUIScriptWnd.OnKeyboard(self,dik,keyboard_action) if (res == false) then local bind = dik_to_bind(dik) if keyboard_action == ui_events.WINDOW_KEY_PRESSED then if dik == DIK_keys.DIK_ESCAPE then self:Close() end end end return res end function UILightControl:Close() self:HideDialog() self:Show(false) Unregister_UI("UILightControl") end